﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;              //命名空间
using System.Data.SqlClient;    //数据库头文件
using System.Data.Sql;         //数据库头文件
using DATA_operate_;          //自定义数据库操作类引用

public partial class design_page_admin_Default : System.Web.UI.Page
{
    DATA_operate data_operate_in_teacher_allhomework = new DATA_operate();   //创建数据库操作类对象


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string sql = "select _public_notice_id,_notice_send_time,_Is_use from _public_notice";
            data_operate_in_teacher_allhomework.Data_bind(sql, GridView_notice_history, "_public_notice_id");

        }
    }

    protected void gridview_rowcommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "gridview_choose")
        {
            Label1.Visible = true;
            TextBox1.Visible = true;
            Button1.Visible = true;
            int index = Convert.ToInt32(e.CommandArgument);
            GridViewRow gvr = GridView_notice_history.Rows[index];
            string str_classname = ((Label)gvr.FindControl("dLabel_uploadid")).Text;
            TextBox1.Text = data_operate_in_teacher_allhomework.dataread("_public_notice", "_notice_content", "_public_notice_id", str_classname);
        }
        if (e.CommandName == "gridview_delete")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            GridViewRow gvr = GridView_notice_history.Rows[index];
            string str_classname = ((Label)gvr.FindControl("dLabel_uploadid")).Text;
            if(data_operate_in_teacher_allhomework.datadelete("_public_notice", "_public_notice_id", str_classname))
            {
                Response.Redirect(Request.RawUrl); 

            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "right", "window.alert('删除失败。请刷新后重试');", true);

            }
    
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Visible = false;
        TextBox1.Visible = false;
        Button1.Visible = false;
    }
}